import AjaxTool from './ajaxTool.js'
const {ajax} = AjaxTool

const baseUrl = 'http://shopback.bluej.cn/api/'
// f_user/report
let myBookUrl = `${baseUrl}f_user/report`
let center = document.querySelector('#center')
let userQuery  = location.search
let needMes = formateQuery(userQuery)
if(!userQuery){
    location.href = '../index.html'
    // return
}

ajax('POST',myBookUrl,JSON.stringify(needMes),'application/json').then(res=>{
    let data = JSON.parse(res)
    const { msg } = data 
    if(msg == '操作成功'){
        // console.log(data.result);
        const {name,day_time,show_id} = data.result[0]
        // console.log(show_id);
        let str = `
            <p>
                姓名:${name}
            </p>
            <p>
                ${day_time}
            </p>
            <p>
                场次：${changeTime(+show_id)}
            </p>
        `
        center.innerHTML = str

    }
}).catch(err=>{
    let str = `
            <p>
                无预约记录
            </p>

        `
        center.innerHTML = str
})








function changeTime(show_id){
    let str = ''
    switch (show_id){
        case 1:
            str='09:00-12:00'
        break
        case 2:
            str='12:00-14:30'
        break
        case 3:
            str='14:30-17:00'
        break
    }
    return str
}

function formateQuery(str) {
    str = str.slice(1)
    let tempArr = str.split('&')
    let obj ={}
    tempArr.forEach(v => {
        let temp = v.split('=')
        obj[temp[0]] = temp[1]
    });
    
    return obj
}